package com.example.hibernate.h.one2many_bag;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

@Entity
@Table(name="T_ITEM")
@SequenceGenerator(name="SEQ_ITEM", sequenceName="SEQ_ITEM", initialValue=1)
@org.hibernate.annotations.Entity(
		dynamicInsert=true,dynamicUpdate=true
	)
public class Item {
	
	@Id @GeneratedValue(generator="SEQ_ITEM")
	private Long id;
	private String name;
	private String description;
	private Double price;
	
	@OneToMany(mappedBy="item", cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
	private Collection<Bid> bids = new ArrayList<Bid>();
	
	public void addBid(Bid bid){
		bid.setItem(this);
		this.bids.add(bid);
	}
	
	public Long getId() {
		return id;
	}

	private void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Double getPrice() {
		return price;
	}

	public void setPrice(Double price) {
		this.price = price;
	}

	public Collection<Bid> getBids() {
		return bids;
	}

	public void setBids(Collection<Bid> bids) {
		this.bids = bids;
	}

	@Override
	public String toString() {
		return "Item [id=" + id + ", name=" + name + ", description=" + description + ", price=" + price + "]";
	}
}
